import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */


/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },

  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboards',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/index',
    alwaysShow: true, // will always show the root menu
    name: 'SystemManager',
    meta: {
      title: '平台管理',
      icon: 'el-icon-s-data'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/system/index'),
        name: 'SystemManager',
        meta: {
          title: '用户管理'
        }
      },
      {
        path: 'homeAdv',
        component: () => import('@/views/system/homeAdv/index'),
        name: 'homeAdv',
        meta: {
          title: '省份管理'
        }
      },
      {
        path: 'operators',
        component: () => import('@/views/system/operators/index'),
        name: 'operators',
        meta: {
          title: '运营商'
        }
      },
      {
        path: 'businesstype',
        component: () => import('@/views/system/businesstype/index'),
        name: 'businesstype',
        meta: {
          title: '业务类型'
        }
      },
      {
        path: 'cardKind',
        component: () => import('@/views/system/cardKind/index'),
        name: 'cardKind',
        meta: {
          title: '包型管理'
        }
      },
      {
        path: 'param',
        component: () => import('@/views/system/parameter/index'),
        name: 'param',
        meta: {
          title: '参数设置'
        }
      },
      {
        path: 'mobile',
        component: () => import('@/views/system/mobile/index'),
        name: 'mobile',
        meta: {
          title: '号段管理'
        }
      },
      {
        path: 'manualRecharge',
        component: () => import('@/views/system/manualRecharge/index'),
        name: 'manualRecharge',
        meta: {
          title: '手工充值'
        }
      },
      {
        path: 'discount',
        component: () => import('@/views/system/discount/index'),
        name: 'discount',
        meta: {
          title: '折扣查询'
        }
      },
      // {
      //   path: 'industryInformation',
      //   component: () => import('@/views/system/industryInformation/index'),
      //   name: 'industryInformation',
      //   meta: {
      //     title: '运营商'
      //   }
      // },
      {
        path: 'loginlog',
        component: () => import('@/views/system/loginlog/index'),
        name: 'loginlog',
        meta: {
          title: '登录日志'
        }
      },
      {
        path: 'blacklist',
        component: () => import('@/views/system/blacklist/index'),
        name: 'blacklist',
        meta: {
          title: '黑名单'
        }
      },
      {
        path: 'cardorder',
        component: () => import('@/views/system/cardorder/index'),
        name: 'cardorder',
        meta: {
          title: '库存管理'
        }
      },
      // {
      //   path: 'cardkindFace',
      //   component: () => import('@/views/system/cardkindFace/index'),
      //   name: 'cardkindFace',
      //   meta: {
      //     title: '充值测试'
      //   }
      // },
      // {
      //   path: 'cardkindFace',
      //   component: () => import('@/views/system/cardkindFace/index'),
      //   name: 'cardkindFace',
      //   meta: {
      //     title: '批量充值'
      //   }
      // }
    ]
  },
  {
    path: '/upinfo',
    component: Layout,
    redirect: '/upinfo/index',
    alwaysShow: true, // will always show the root menu
    name: 'upinfo',
    meta: {
      title: '供货管理',
      icon: 'el-icon-bank-card'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/upInfo/index'),
        name: 'upinfo',
        meta: {
          title: '供货账户'
        }
      },
      {
        path: 'upAccountTurnover',
        component: () => import('@/views/upInfo/upAccountTurnover/index'),
        name: 'upAccountTurnover',
        meta: {
          title: '充值记录'
        }
      },
      {
        path: 'uprecordCount',
        component: () => import('@/views/upInfo/uprecordCount/index'),
        name: 'uprecordCount',
        meta: {
          title: '充值统计'
        }
      },
      {
        path: 'upProduct',
        component: () => import('@/views/upInfo/upProduct/index'),
        name: 'upProduct',
        meta: {
          title: '产品配置'
        }
      },
      {
        path: 'producttimerUp',
        component: () => import('@/views/upInfo/producttimer/index'),
        name: 'producttimerUp',
        meta: {
          title: '调价记录',
        }
      },
      {
        path: 'upOrder',
        component: () => import('@/views/upInfo/upOrder/index'),
        name: 'upOrder',
        meta: {
          title: '订单管理'
        }
      },
      {
        path: 'downProductMatch',
        component: () => import('@/views/upInfo/downProductMatch/index'),
        name: 'downProductMatch',
        meta: {
          title: '产品查询'
        }
      },
      {
        path: 'uporderlog',
        component: () => import('@/views/upInfo/uporderlog/index'),
        name: 'uporderlog',
        meta: {
          title: '订单日志'
        }
      },
      {
        path: 'uporderrefund',
        component: () => import('@/views/upInfo/uporderrefund/index'),
        name: 'uporderrefund',
        meta: {
          title: '退款记录'
        }
      },
      {
        path: 'debitUplog',
        component: () => import('@/views/upInfo/debitUplog/index'),
        name: 'debitUplog',
        meta: {
          title: '扣款记录'
        }
      },
      {
        path: 'upproductlog',
        component: () => import('@/views/upInfo/upproductlog/index'),
        name: 'upproductlog',
        meta: {
          title: '产品日志'
        }
      },
      {
        path: 'downbillUp',
        component: () => import('@/views/upInfo/downbillUp/index'),
        name: 'downbillUp',
        meta: {
          title: '对账单'
        }
      },
      {
        path: 'exportlistUp',
        component: () => import('@/views/upInfo/exportlistUp/index'),
        name: 'exportlistUp',
        meta: {
          title: '导出列表'
        }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    alwaysShow: true, // will always show the root menu
    name: 'user',
    meta: {
      title: '分销管理',
      icon: 'el-icon-coin'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/user/index'),
        name: 'UserManager',
        meta: {
          title: '分销账户'
        }
      },
      {
        path: 'downrechargerecord',
        component: () => import('@/views/user/downrechargerecord/index'),
        name: 'downrechargerecord',
        meta: {
          title: '充值记录',
        }
      },
      {
        path: 'downrechargerecordcount',
        component: () => import('@/views/user/downrechargerecordcount/index'),
        name: 'downrechargerecordcount',
        meta: {
          title: '充值统计',
        }
      },
      {
        path: 'downProduct',
        component: () => import('@/views/user/downProduct/index'),
        name: 'downProduct',
        meta: {
          title: '产品配置',
        }
      },
      {
        path: 'producttimer',
        component: () => import('@/views/user/producttimer/index'),
        name: 'producttimer',
        meta: {
          title: '调价记录',
        }
      },
      {
        path: 'matchingstrategy',
        component: () => import('@/views/user/matchingstrategy/index'),
        name: 'matchingstrategy',
        meta: {
          title: '配置查询',
        }
      },
      {
        path: 'downOrder',
        component: () => import('@/views/user/downOrder/index'),
        name: 'downOrder',
        meta: {
          title: '订单管理',
        }
      },
      {
        path: 'downorderlog',
        component: () => import('@/views/user/downorderlog/index'),
        name: 'downorderlog',
        meta: {
          title: '订单日志',
        }
      },
      {
        path: 'downorderrefund',
        component: () => import('@/views/user/downorderrefund/index'),
        name: 'downorderrefund',
        meta: {
          title: '退款记录',
        }
      },
      {
        path: 'debitlog',
        component: () => import('@/views/user/debitlog/index'),
        name: 'debitlog',
        meta: {
          title: '扣款记录',
        }
      },
      {
        path: 'downprolog',
        component: () => import('@/views/user/downprolog/index'),
        name: 'downprolog',
        meta: {
          title: '产品日志',
        }
      },
      {
        path: 'zerobalance',
        component: () => import('@/views/user/zerobalance/index'),
        name: 'zerobalance',
        meta: {
          title: '零点余额',
        }
      },
      {
        path: 'downbill',
        component: () => import('@/views/user/downbill/index'),
        name: 'downbill',
        meta: {
          title: '对账单',
        }
      },
      {
        path: 'exportlist',
        component: () => import('@/views/user/exportlist/index'),
        name: 'exportlist',
        meta: {
          title: '导出列表',
        }
      }
    ]
  },
  {
    path: '/export',
    component: Layout,
    redirect: '/export/CountProfit',
    name: 'export',
    meta: {
      title: '统计管理',
      icon: 'excel'
    },
    children: [
      {
        path: 'CountProfit',
        component: () => import('@/views/count/countprofit/index'),
        name: 'CountProfit',
        meta: { title: '利润统计' }
      },
      {
        path: 'countpProfitRate',
        component: () => import('@/views/count/countpProfitRate/index'),
        name: 'countpProfitRate',
        meta: { title: '利润率' }
      },
      {
        path: 'CountUpFlow',
        component: () => import('@/views/count/countUpFlow/index'),
        name: 'CountUpFlow',
        meta: { title: '供货商产品统计' }
      },
      {
        path: 'countDownFlow',
        component: () => import('@/views/count/countDownFlow/index'),
        name: 'countDownFlow',
        meta: { title: '分销商产品统计' }
      },
      {
        path: 'countDownProfit',
        component: () => import('@/views/count/countDownProfit/index'),
        name: 'countDownProfit',
        meta: { title: '分销商利润统计' }
      },
      {
        path: 'findDownOrderCount',
        component: () => import('@/views/count/findDownOrderCount/index'),
        name: 'findDownOrderCount',
        meta: { title: '三网统计' }
      },
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const downasyncRoutes = [
  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    alwaysShow: true, // will always show the root menu
    name: 'user',
    meta: {
      title: '分销管理',
      icon: 'lock'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/user/index'),
        name: 'UserManager',
        meta: {
          title: '分销账户'
        }
      },
      {
        path: 'downrechargerecord',
        component: () => import('@/views/user/downrechargerecord/index'),
        name: 'downrechargerecord',
        meta: {
          title: '充值记录',
        }
      },
      {
        path: 'downrechargerecordcount',
        component: () => import('@/views/user/downrechargerecordcount/index'),
        name: 'downrechargerecordcount',
        meta: {
          title: '充值统计',
        }
      },
      {
        path: 'downOrder',
        component: () => import('@/views/user/downOrder/index'),
        name: 'downOrder',
        meta: {
          title: '订单管理',
        }
      },
      {
        path: 'downProduct',
        component: () => import('@/views/user/downProduct/index'),
        name: 'downProduct',
        meta: {
          title: '产品管理',
        }
      },
      {
        path: 'downorderrefund',
        component: () => import('@/views/user/downorderrefund/index'),
        name: 'accountTurnover',
        meta: {
          title: '退款记录',
        }
      },
      {
        path: 'debitlog',
        component: () => import('@/views/user/debitlog/index'),
        name: 'debitlog',
        meta: {
          title: '扣款记录',
        }
      },
      // {
      //   path: 'downprolog',
      //   component: () => import('@/views/user/downprolog/index'),
      //   name: 'downprolog',
      //   meta: {
      //     title: '产品日志',
      //   }
      // },
      {
        path: 'zerobalance',
        component: () => import('@/views/user/zerobalance/index'),
        name: 'zerobalance',
        meta: {
          title: '零点余额',
        }
      },
      {
        path: 'exportlist',
        component: () => import('@/views/user/exportlist/index'),
        name: 'exportlist',
        meta: {
          title: '导出列表',
        }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]


const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
